home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / redo / redoFileRemoveSlotted.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  8.0 KB  |  326 lines

  1. /*
  2.  *   $RCSfile: redoFileRemoveSlotted.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:55:58 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38.  
  39. #include "sysdefs.h"
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "tid.h"
  46. #include "io.h"
  47. #include "lock.h"
  48. #include "object.h"
  49. #include "msgdefs.h"
  50. #include "thread.h"
  51. #include "latch.h"
  52. #include "semaphore.h"
  53. #include "link.h"
  54. #include "lsn.h"
  55. #include "bf.h"
  56. #include "log.h"
  57. #include "pool.h"
  58. #include "volume.h"
  59. #include "logrecs.h"
  60. #include "trans.h"
  61. #include "bitmap.h"
  62. #include "file.h"
  63. #include "openlog.h"
  64. #include "bf_extfuncs.h"
  65. #include "bm_extfuncs.h"
  66. #include "fi_intfuncs.h"
  67. #include "trans_extfuncs.h"
  68. #include "redo_extfuncs.h"
  69. #include "logaction.h"
  70. #include "util_funcs.h"
  71. #include "thread_globals.h"
  72. #include "bf_globals.h"
  73. #include "log_globals.h"
  74. #include "log_extfuncs.h"
  75.  
  76.  
  77. /*
  78.  *    This function redoes the setting of the file root page pointers
  79.  *    to the first and last logical pages in the file, and the 
  80.  *    setting of the nextLogicalPid field of the last page in the
  81.  *    file
  82.  */
  83.  
  84.  void
  85. redoFileRemoveSlotted (
  86.  
  87.     LOGRECORDHDR        *record 
  88. )
  89. {
  90.  
  91.     PID                *rootPID;
  92.     PID                lastPID;
  93.     NODEPAGE        *nodePage;
  94.     SLOTTEDPAGE        *slottedPage;
  95.     GROUPLINK        *groupLink;
  96.     BOOL            firstPage;
  97.     DIRTYPAGEINFO    *dirtyInfo;
  98.     LRC                *lrc;
  99.  
  100.  
  101.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_1, ("lsn:%d", record->recordLSN.offset));
  102.     SM_ASSERT(LEVEL_3, record->type == LOG_REC_TYPE_COMPENSATION);
  103.  
  104.     /*
  105.      *    get a pointer to the file root page id
  106.      *    get flag for whether this is the first page in the file
  107.      *    get pid of new page added to file
  108.      */
  109.     rootPID = &(record->actionPid);
  110.     firstPage = *(BOOL*) GET_LOG_IMAGE(record, 0);
  111.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("file root page:%d", rootPID->page));
  112.     if (!firstPage) {
  113.  
  114.         /*
  115.          *    Get a pointer to the last slotted page in the file
  116.          *    and a pointer to the log record lrc for this page
  117.          */
  118.         lastPID.page = *(SHORTPID*) GET_LOG_IMAGE(record, 1);
  119.         lastPID.volid = rootPID->volid;
  120.         lrc = (LRC*) GET_LOG_IMAGE(record, 2);
  121.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("last slotted page:%d", lastPID.page));
  122.     }
  123.  
  124.     /*
  125.      *    check to see if the root page is in the dirty page list
  126.      */
  127.     if ((dirtyInfo = searchDirtyPageTable(rootPID)) == NULL)    {
  128.  
  129.         /*
  130.          *    don't need to redo
  131.          */
  132.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty page not present"));
  133.         goto handle_page_link;
  134.     }
  135.  
  136.     /*
  137.      *  check to see if the lrc on the page is greater than
  138.      *  the lrc in the log record.
  139.      *  Also check the lsn for the case of pages which never made it
  140.      *  back from the client.
  141.      */
  142.     if (CHECK_PAGE_LRC_LESS_DIRTYINFO(record->actionLRC, record->recordLSN, dirtyInfo)) {
  143.  
  144.         /*
  145.          *  don't need to redo
  146.          */
  147.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty info page lrc later"));
  148.         return;
  149.     }
  150.  
  151.  
  152.     /*
  153.      * Read in first page of file and grab node type
  154.      */
  155.     if ((groupLink = bf_ReadPage(UserBufGroup, rootPID, FILE_PAGE2SIZE, BF_SEM)) == NULL) {
  156.  
  157.         SM_ERROR(TYPE_FATAL, Active->errno);
  158.     }
  159.  
  160.     /*
  161.      *    get a pointer to the node page
  162.      */
  163.     nodePage = (NODEPAGE *) groupLink->bufFrame;
  164.  
  165.     /*
  166.      *    check to see if the lrc on the page is greater than
  167.      *    the lrc in the log record
  168.      */
  169.     if (compareLRC( &(record->actionLRC), &(nodePage->header.lrc)) <= 0)    {
  170.  
  171.         /*
  172.          *    don't need to redo
  173.          *    mark the page lrc
  174.          */
  175.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("actual page lrc later"));
  176.         dirtyInfo->lrc = nodePage->header.lrc;
  177.  
  178.         /*
  179.          *    release the page
  180.          */
  181.         signalSemaphore( &(groupLink->pageHash->semaphore) );
  182.         bf_UnfixPage(groupLink, BF_DEFAULT, FALSE);
  183.         goto handle_page_link;
  184.     }
  185.  
  186.     /*
  187.      *    See if this was the first page added and then update the
  188.      *    proper pointers
  189.      */
  190.     if (firstPage) {
  191.         
  192.         /*
  193.          *    Update the first and the last
  194.          */
  195.         SM_ASSERT(LEVEL_3, nodePage->header.firstLogicalNode != NULLPID && nodePage->header.lastLogicalNode != NULLPID);
  196.         nodePage->header.firstLogicalNode = NULLPID;
  197.         nodePage->header.lastLogicalNode = NULLPID;
  198.  
  199.     } else {
  200.  
  201.         /*
  202.          *    Update the only the last
  203.          */
  204.         nodePage->header.lastLogicalNode = lastPID.page;
  205.     }
  206.  
  207.     /*
  208.      *    mark the LRC on the page
  209.      *    Set up the firstLSN/LRC for the page
  210.      */
  211.     nodePage->header.lrc = record->actionLRC;
  212.     DEPEND_LOG(groupLink->pageHash, 0, &(record->recordLSN), &(record->actionLRC));
  213.     TRPRINT(TR_RECOVER, TR_LEVEL_2, ("marking new page lrc:%d", nodePage->header.lrc.count));
  214.  
  215.     /*
  216.      *    release  the page semaphore
  217.      */
  218.     signalSemaphore( &(groupLink->pageHash->semaphore) );
  219.  
  220.     /*
  221.      *    release and dirty the page
  222.      */
  223.     bf_UnfixPage(groupLink, BF_DEFAULT, TRUE);
  224.  
  225. /*
  226.  *    Update link on last page in the file
  227.  */
  228. handle_page_link:
  229.  
  230.     /*
  231.      *    If this is not the first page, then update the link on the
  232.      *    last page
  233.      */
  234.     if (!firstPage) {
  235.  
  236.         /*
  237.          *    check to see if the last page is in the dirty page list
  238.          */
  239.         if ((dirtyInfo = searchDirtyPageTable(&lastPID)) == NULL)    {
  240.  
  241.             /*
  242.              *    don't need to redo
  243.              */
  244.             TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty page not present"));
  245.             return;
  246.         }
  247.  
  248.         /*
  249.          *  check to see if the lrc on the page is greater than
  250.          *  the lrc in the log record
  251.          */
  252.         if (compareLRC( lrc, &(dirtyInfo->lrc) ) < 0)  {
  253.  
  254.             /*
  255.              *  don't need to redo
  256.              */
  257.             TRPRINT(TR_RECOVER, TR_LEVEL_2, ("dirty info page lrc later"));
  258.             return;
  259.         }
  260.  
  261.         /*
  262.          *  Make sure the comparison was correct
  263.          */
  264.         SM_ASSERT(LEVEL_3, compareLSN( &(record->recordLSN), &(dirtyInfo->lsn)) >= 0);
  265.  
  266.         /*
  267.          * Read in last page of file
  268.          */
  269.         if ((groupLink = bf_ReadPage(UserBufGroup, &lastPID, SLOTTED_PAGE2SIZE, BF_SEM)) == NULL) {
  270.  
  271.             SM_ERROR(TYPE_FATAL, Active->errno);
  272.         }
  273.  
  274.         /*
  275.          *    get a pointer to the node page
  276.          */
  277.         slottedPage = (SLOTTEDPAGE *) groupLink->bufFrame;
  278.  
  279.         /*
  280.          *    check to see if the lrc on the page is greater than
  281.          *    the lrc in the log record.  Note that the comparison is 
  282.          *    < not <= since the lrc was not incremented upon the
  283.          *    generation of this log record.
  284.          */
  285.         if (compareLRC( lrc, &(slottedPage->header.lrc)) < 0)    {
  286.  
  287.             /*
  288.              *    don't need to redo
  289.              *    mark the page lrc
  290.              */
  291.             TRPRINT(TR_RECOVER, TR_LEVEL_2, ("actual page lrc later"));
  292.             dirtyInfo->lrc = nodePage->header.lrc;
  293.  
  294.             /*
  295.              *    release the page
  296.              */
  297.             signalSemaphore( &(groupLink->pageHash->semaphore) );
  298.             bf_UnfixPage(groupLink, BF_DEFAULT, FALSE);
  299.             return;
  300.         }
  301.  
  302.         /*
  303.          *    Redo the link update
  304.          */
  305.         slottedPage->header.nextLogicalPid = NULLPID;
  306.  
  307.         /*
  308.          *    don't mark the LRC on the page
  309.          *    Set up the firstLSN/LRC for the page
  310.          */
  311.         /*slottedPage->header.lrc = *lrc;*/
  312.         DEPEND_LOG(groupLink->pageHash, 0, &(record->recordLSN), lrc);
  313.         TRPRINT(TR_RECOVER, TR_LEVEL_2, ("marking new page lrc:%d", slottedPage->header.lrc.count));
  314.  
  315.         /*
  316.          *    release  the page semaphore
  317.          */
  318.         signalSemaphore( &(groupLink->pageHash->semaphore) );
  319.  
  320.         /*
  321.          *    release and dirty the page
  322.          */
  323.         bf_UnfixPage(groupLink, BF_DEFAULT, TRUE);
  324.     }
  325. }
  326.